Date.prototype.Format = function(fmt) {
	var o = {
		"M+": this.getMonth() + 1, //月份 
		"d+": this.getDate(), //日 
		"H+": this.getHours(), //小时 
		"m+": this.getMinutes(), //分 
		"s+": this.getSeconds(), //秒 
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
		"S": this.getMilliseconds() //毫秒 
	};
	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" +
			o[k]).substr(("" + o[k]).length)));
	return fmt;
}

Date.prototype.UUID = function(serviceNo) {
	var d = this.getTime();
	var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx-'.replace(/[xy]/g, function(c) {
		var r = (d + Math.random() * 16) % 16 | 0;
		d = Math.floor(d / 16);
		return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
	});
	return uuid + serviceNo;
}
// es6 find方法
Array.prototype.find = function(cb){
	for(var i = 0 ; i < this.length; i++){
		if(cb(this[i])){
			return this[i];
		}
	}
	return null
}

/*'yyyy-MM-dd HH:mm:ss'格式的字符串转日期*/
function stringYYYYMMDDHHMMSSToDate(str) {
	var tempStrs = str.split(" ");
	var dateStrs = tempStrs[0].split("-");
	var year = parseInt(dateStrs[0], 10);
	var month = parseInt(dateStrs[1], 10) - 1;
	var day = parseInt(dateStrs[2], 10);
	var timeStrs = tempStrs[1].split(":");
	var hour = parseInt(timeStrs[0], 10);
	var minute = parseInt(timeStrs[1], 10);
	var second = parseInt(timeStrs[2], 10);
	var date = new Date(year, month, day, hour, minute, second);
	return date;
}

/*'yyyy-MM-dd HH:mm'格式的字符串转日期*/
function stringYYYYMMDDHHMMToDate(str) {
	var tempStrs = str.split(" ");
	var dateStrs = tempStrs[0].split("-");
	var year = parseInt(dateStrs[0], 10);
	var month = parseInt(dateStrs[1], 10) - 1;
	var day = parseInt(dateStrs[2], 10);
	var timeStrs = tempStrs[1].split(":");
	var hour = parseInt(timeStrs[0], 10);
	var minute = parseInt(timeStrs[1], 10);
	var date = new Date(year, month, day, hour, minute);
	return date;
}

// 获取url中的参数  
function getUrlParam (name) {  
     var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");  
     var r = window.location.search.substr(1).match(reg);  
     if (r!= null) {  
        return unescape(r[2]);  
     }else{  
        return null;  
     }  
}  

function getDate(id){
	var info = document.getElementById(id);
	info.addEventListener('tap', function() {
		var dDate = new Date();
		var minDate = new Date();
		minDate.setFullYear(2010, 0, 1);
		var maxDate = new Date();
		maxDate.setFullYear(2050, 11, 31);
		plus.nativeUI.pickDate(function(e) {
			var d = e.date;
			info.innerText =  d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate();
		}, function(e) {
			info.innerText = "请选择时间";
		}, {
			title: "请选择时间",
			date: dDate,
			minDate: minDate,
			maxDate: maxDate
		});
	})
}

// 获取日期为星期几，day为日期类型
function getWeekDate(day) {
   var weeks = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
   var week = weeks[day.getDay()];
   return week;
}

// 备件状态名称
function partStatusName(status) {
	if (status == 0) {
		return "未处理"
	} else if (status == 1) {
		return "需订货"
	} else if (status == 2) {
		return "已订货"
	} else if (status == 3) {
		return "仓库待发货"
	} else if (status == 4) {
		return "已发货"
	} else if (status == 5) {
		return "已收货"
	} else if (status == 6) {
		return "上门取件"
	} else if (status == 7) {
		return "已还货"
	} else if (status == 8) {
		return "仓库收到还库"
	} else if (status == 9) {
		return "系统入库"
	} else if (status == 10) {
		return "已使用"
	} else if (status == 11) {
		return "已消耗"
	} else if (status == 12) {
		return "坏件入库"
	} else if (status == 13) {
		return "仓库收货待确认"
	} else if (status == 14) {
		return "已转移"
	} else if (status == 15) {
		return "特殊借件"
	} else if (status == 16) {
		return "Depot使用"
	} else if (status == 17) {
		return "无库存"
	} else if (status == 18) {
		return "待出库"
	} else if (status == 19) {
		return "异常收货"
	}
}

// 空字符串处理
function emptyStr(str) {
	if (str) {
		return str;
	} else {
		return "";
	}
}

var JS = {
        IsNullOrEmpty:function(str){ 
            if(typeof(str)=="undefined") return true; 
            if(str==null) return true;
			if(str=="null") return true;
            if(str=="") return true;
            return false;
        },//IsNullOrEmpty
        GetRadioValue:function(radioName)
        {
            var radios = document.getElementsByName(radioName);
            for(var i = 0 ; i< radios.length; i++)
            {
                var radio = radios.item(i);
                if(radio.checked)
                {
                    if(JS.IsNullOrEmpty(radio.value)) return undefined;
                    return radio.value;
                }
            }
            return undefined;
        },//GetRadioValue
		ClearRadioChecked:function(radioName) {
			var radios = document.getElementsByName(radioName);
			for(var i = 0 ; i< radios.length; i++)
			{
			    if(radios.item(i).checked)
			    {
			        radios.item(i).checked = null
			    }
			}
		},//ClearRadioChecked
        GetCheckboxValue:function(checkboxName)
        {
            var checkboxs = document.getElementsByName(checkboxName);
            var ck = new Array();
            var j  =  0;
            for(var i = 0 ; i< checkboxs.length; i++)
            {
                var checkbox = checkboxs[i];
                if(checkbox.checked)
                {
                    if(JS.IsNullOrEmpty(checkbox.value)) return undefined;
                    ck[j] = checkbox.value;
                    j++;
                }
            }
            return j == 0 ? undefined : ck.join();
        },//GetCheckboxValue
        GetSelectValue:function(selectId)
        {
            var select = document.getElementById(selectId);
            var options = select.options;
            for(var i = 0 ; i<options.length ;i++)
            {
                var option = options[i];
                if(option.selected)
                {
                    if(JS.IsNullOrEmpty(option.value)) return undefined;
                    return option.value;
                }
            }
            return undefined;
        }//GetSelectValue
}
// 字典下拉添加请选择
function dictAddQxz(data, qxzName) {
	if (qxzName == "" || qxzName == "undefined" || qxzName == null) {
		qxzName = "请选择";
	}
	var res = new Array();
	res.push({"value" : "", "text" : qxzName});
	if (data) {
		for (var i = 0; i < data.length; i ++) {
			res.push(data[i]);
		}
	}
	console.log(JSON.stringify(res))
	return res;
}


function getLast3Month() { //获取近三个月时间
	var now = new Date();
	var year = now.getFullYear();
	var month = now.getMonth() + 1;//0-11表示1-12月
	var day = now.getDate();
	var dateObj = {};
	if (parseInt(month) < 10) {
		month = "0" + month;
	}
	if (parseInt(day) < 10) {
		day = "0" + day;
	}

	dateObj.now = year + '-' + month + '-' + day;

	if (parseInt(month) == 1) {//如果是1月份，则取上一年的10月份
		dateObj.last = (parseInt(year) - 1) + '-10-' + day;
		return dateObj;
	}
	if (parseInt(month) == 2) {//如果是2月份，则取上一年的11月份
		dateObj.last = (parseInt(year) - 1) + '-11-' + day;
		return dateObj;
	}
	if (parseInt(month) == 3) {//如果是3月份，则取上一年的12月份
		dateObj.last = (parseInt(year) - 1) + '-12-' + day;
		return dateObj;
	}

	var preSize = new Date(year, parseInt(month) - 3, 0).getDate();//开始时间所在月的总天数
	if (preSize < parseInt(day)) {
		// 开始时间所在月的总天数<本月总天数，比如当前是5月30日，在2月中没有30，则取下个月的第一天(3月1日)为开始时间
		let resultMonth = parseInt(month) - 2 < 10 ? ('0' + parseInt(month) - 2) : (parseInt(month) - 2);
		dateObj.last = year + '-' + resultMonth + '-01';
		return dateObj;
	}

	if (parseInt(month) <= 10) {
		dateObj.last = year + '-0' + (parseInt(month) - 3) + '-' + day;
		return dateObj;
	} else {
		dateObj.last = year + '-' + (parseInt(month) - 3) + '-' + day;
		return dateObj;
	}

}
function getLastWeek() {
	var end = new Date()
	var start = new Date()
	start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
	var date = [new Date(start).Format("yyyy-MM-dd"), new Date(end).Format("yyyy-MM-dd")]
	return date
}


/** 
 * 获取上个月日期
 * @param {String} date  非必填 包含yy-mm-dd 的时间类型
 */
function getLast1Month(date) { //获取近1个月时间
	var now = date? new Date(date) : new Date();
	var year = now.getFullYear();
	var month = now.getMonth() + 1;//0-11表示1-12月
	var day = now.getDate();
	var dateObj = {};
	if (parseInt(month) < 10) {
		month = "0" + month;
	}
	if (parseInt(day) < 10) {
		day = "0" + day;
	}

	dateObj.now = year + '-' + month + '-' + day;

	if (parseInt(month) == 1) {//如果是1月份，则取上一年的10月份
		dateObj.last = (parseInt(year) - 1) + '-12-' + day;
		return dateObj;
	}
	var preSize = new Date(year, parseInt(month) - 1, 0).getDate();//开始时间所在月的总天数
	if (preSize < parseInt(day)) {
		// 开始时间所在月的总天数<本月总天数，比如当前是5月30日，在2月中没有30，则取下个月的第一天(3月1日)为开始时间
		let resultMonth = parseInt(month) - 0 < 10 ? ('0' + parseInt(month) - 0) : (parseInt(month) - 0);
		dateObj.last = year + '-' + resultMonth + '-01';
		return dateObj;
	}

	if (parseInt(month) <= 10) {
		dateObj.last = year + '-0' + (parseInt(month) - 1) + '-' + day;
		return dateObj;
	} else {
		dateObj.last = year + '-' + (parseInt(month) - 1) + '-' + day;
		return dateObj;
	}

}